package com.xxl.services.impl;

import com.xxl.bean.Student;
import com.xxl.dao.StudentDao;
import com.xxl.dao.impl.StudentDaoImpl;
import com.xxl.services.StudentService;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class StudentServiceImpl implements StudentService {
    StudentDao studentDao = new StudentDaoImpl();
    @Override
    public void addOrUpdate(String studentId,String studentName,String classesName) throws IOException {
        if (studentId.length()>0){
            studentDao.updateStudent(studentId, studentName, classesName);
        }else {
            studentDao.addStudent(studentName, classesName);
        }
    }

    @Override
    public boolean delete(String studentId) {
        return studentDao.delByStudentId(studentId);
    }

    @Override
    public void listAddStudent(List list) throws SQLException {
        ResultSet sel = studentDao.getAll();
        while (true){
            try {
                if (!sel.next()){
                    break;
                }
            }finally {
                System.out.println("StudentServlet.listAddStudent");
            }
            try {
                Student stu = new Student(sel.getString("studentId"), sel.getString("studentName"), sel.getString("classesName"));
                list.add(stu);
            }finally {
                System.out.println("StudentServlet.listAddStudent");
            }
        }
    }

}
